package br.foton.la.agenda.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;

@NamedQueries({
	@NamedQuery(name = Motorista.GET_TRAVELS_FOR_DRIVER, query = "select m from Motorista m join fetch m.viagens")
})
@Entity
@PrimaryKeyJoinColumn(name = "id")
@Inheritance(strategy = InheritanceType.JOINED)
public class Motorista extends Pessoa implements Serializable {
	private static final long serialVersionUID = 1L;
	public static final String GET_TRAVELS_FOR_DRIVER = "Motorista.GET_VIAGENS_BY_MOTORISTA";
	
	@Column(nullable = false)
	private char categoria;
	@OneToOne(cascade = CascadeType.ALL)
	private Carreta carreta;
	@Column(columnDefinition = "Decimal(3,2)")
	private double comissao;
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "motorista")
	private List<Viagem> viagens;
	
	public Motorista(String nome, String rg, String cpf, String login, String senha) {
		super(nome, rg, cpf, login, senha);
	}

	public Motorista() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public String toString() {
		return "Motorista [id=" + getId() + ", categoria=" + categoria
				+ ", carreta=" + carreta + ", comissao=" + comissao + "]";
	}

	public char getCategoria() {
		return categoria;
	}

	public void setCategoria(char categoria) {
		this.categoria = categoria;
	}

	public Carreta getCarreta() {
		return carreta;
	}

	public void setCarreta(Carreta carreta) {
		this.carreta = carreta;
	}

	public double getComissao() {
		return comissao;
	}

	public void setComissao(double comissao) {
		this.comissao = comissao;
	}

	public List<Viagem> getViagens() {
		return viagens;
	}

	public void setViagens(List<Viagem> viagens) {
		this.viagens = viagens;
	}

}
